<?php
	
	////////////////////////////////////////////////////////////////////////
	// Colours :D
	////////////////////////////////////////////////////////////////////////
	if (!function_exists('html2rgb')):
	function html2rgb($colour)
	{
		if ($colour[0] == '#')$colour = substr($colour, 1);
	
		if (strlen($colour) == 6)
		    list($r, $g, $b) = array($colour[0].$colour[1],
					    $colour[2].$colour[3],
					    $colour[4].$colour[5]);
	
		elseif (strlen($colour) == 3) list($r, $g, $b) = array($colour[0].$colour[0], $colour[1].$colour[1], $colour[2].$colour[2]);
		else return false;
	
		$r = hexdec($r); $g = hexdec($g); $b = hexdec($b);
	
		return array($r, $g, $b);
	}
	endif;
	
	if (!function_exists('rgb2html')):
	function rgb2html($r, $g=-1, $b=-1)
	{
		if (is_array($r) && sizeof($r) == 3) list($r, $g, $b) = $r;
	
		$r = intval($r); 
		$g = intval($g);
		$b = intval($b);
	
		$r = dechex($r<0?0:($r>255?255:$r));
		$g = dechex($g<0?0:($g>255?255:$g));
		$b = dechex($b<0?0:($b>255?255:$b));
	
		$color = (strlen($r) < 2?'0':'').$r;
		$color .= (strlen($g) < 2?'0':'').$g;
		$color .= (strlen($b) < 2?'0':'').$b;
		return '#'.$color;
	}
	endif;
	
	if (!function_exists('darkenHex')):
	function darkenHex( $hex, $darken )
	{
		$rgb = html2rgb( $hex );
		$red = $rgb[0];
		$green = $rgb[1];
		$blue = $rgb[2];
		// return as hex
		return rgb2html( $red*$darken, $green*$darken, $blue*$darken );
	}
	endif;
	
	////////////////////////////////////////////////////////////////////////
	// @Return a html colour from a GET query
	////////////////////////////////////////////////////////////////////////
	if (!function_exists('parseQueryColour')):
	function parseQueryColour( $queryName='textcol' )
	{
		$colour = $_GET[ $queryName ];
		return( parseColour($colour) );
	}
	endif;
	
	
	// check to see what format the query is in... is it a hexadecimal number? (FFEEAA)
	if (!function_exists( 'parseColour' )):
	function parseColour( $colour )
	{
		if (is_numeric ($colour)) return $colour;
		if (strlen($colour) == 6) return "#" . $colour;
		
		// comma delimited RGB trio (3,45,255)
		$splitRGB = explode(',', $colour);     	 // R.G.B.
		return rgb2html( $splitRGB[0], $splitRGB[1], $splitRGB[2] );
	}
	endif; 

	$outputVars = array
	( 
		'print' => false,
		'baseline' => 22,
		'textcol' => '333333',
		'linkcol' => 'aa3333'
	);					

	// store get vars in this array
	$domain = $_SERVER['HTTP_HOST'];			// find out the domain
	$path = $_SERVER['SCRIPT_NAME'];			// find out the path to the current file
	$queryString = $_SERVER['QUERY_STRING'];		// find out the QueryString
	$url = "http://" . $domain . $path;			// put it all together
	
	$parsed_url = parse_url( $url  .'?'. $queryString );	
	
	if ( isset( $parsed_url['query'] ) )
	{
	$url_query = $parsed_url['query'];
	parse_str($url_query, $fields);
	
	// transfer each query to the defaults
	foreach ($fields as $key => $val)
	{
	  $outputVars[ $key ] = $val;
	}
}
    // ADD CSS HEADER *ONCE*
	header('Content-type: text/css');
	header('Expires: '.gmdate('D, d M Y H:i:s',time() + (60 * 60 * 24 * 30)).' GMT');	
    
	$baseline = $outputVars[ 'baseline' ];
	$linkActiveColour = parseQueryColour( 'linkcol' );
	$rgb = html2rgb($linkActiveColour);
	$rgba = "rgba(255,255,255,.2)";
	$darkActiveColour = darkenHex( $linkActiveColour, 0.5 );
?>


.button,button,input[type="submit"],input[type="reset"],input[type="button"],
.radius-tl
{
	-moz-border-top-left-radius:<?php echo ($baseline*0.25) . "px"; ?>;
	-webkit-border-top-left-radius:<?php echo ($baseline*0.25) . "px"; ?>;
	border-top-left-radius:<?php echo ($baseline*0.25) . "px"; ?>;
}

.button,button,input[type="submit"],input[type="reset"],input[type="button"],
.radius-tr
{
	-moz-border-top-right-radius:<?php echo ($baseline*0.25) . "px"; ?>;
	-webkit-border-top-right-radius:<?php echo ($baseline*0.25) . "px"; ?>;
	border-top-right-radius:<?php echo ($baseline*0.25) . "px"; ?>;
}

.button,button,input[type="submit"],input[type="reset"],input[type="button"],
.radius-br
{
	-moz-border-bottom-right-radius:<?php echo ($baseline*0.25) . "px"; ?>;
	-webkit-border-bottom-right-radius:<?php echo ($baseline*0.25) . "px"; ?>;
	border-bottom-right-radius:<?php echo ($baseline*0.25) . "px"; ?>;
}

.button,button,input[type="submit"],input[type="reset"],input[type="button"],
.radius-bl
{
	-moz-border-bottom-left-radius:<?php echo ($baseline*0.25) . "px"; ?>;
	-webkit-border-bottom-left-radius:<?php echo ($baseline*0.25) . "px"; ?>;
	border-bottom-left-radius:<?php echo ($baseline*0.25) . "px"; ?>;
}

/* Backgrounds */
.bg-inactive
{
	background: #ddd; /* Old browsers */
	background: #ddd -moz-linear-gradient(top, rgba(255,255,255,.3) 0%, rgba(0,0,0,.3) 100%); /* FF3.6+ */
	background: #ddd -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,.3)), color-stop(100%,rgba(0,0,0,.3))); /* Chrome,Safari4+ */
	background: #ddd -webkit-linear-gradient(top, rgba(255,255,255,.3) 0%,rgba(0,0,0,.3) 100%); /* Chrome10+,Safari5.1+ */
	background: #ddd -o-linear-gradient(top, rgba(255,255,255,.3) 0%,rgba(0,0,0,.3) 100%); /* Opera11.10+ */
	background: #ddd -ms-linear-gradient(top, rgba(255,255,255,.3) 0%,rgba(0,0,0,.3) 100%); /* IE10+ */
	background: #ddd linear-gradient(top, rgba(255,255,255,.3) 0%,rgba(0,0,0,.3) 100%); /* W3C */
}


/* Background Active Link Colour -> Darkened */
.button,button,
input[type="submit"],input[type="reset"],input[type="button"],
.bg-active
{
	background: <?php echo $linkActiveColour; ?>; /* Old browsers */
	background: <?php echo $linkActiveColour; ?> -moz-linear-gradient(top, <?php echo $rgba; ?> 0%, rgba(0,0,0,.2) 100%); /* FF3.6+ */
	background: <?php echo $linkActiveColour; ?> -webkit-gradient(linear, left top, left bottom, color-stop(0%,<?php echo $rgba; ?>), color-stop(100%,rgba(0,0,0,.2))); /* Chrome,Safari4+ */
	background: <?php echo $linkActiveColour; ?> -webkit-linear-gradient(top, <?php echo $rgba; ?> 0%,rgba(0,0,0,.2) 100%); /* Chrome10+,Safari5.1+ */
	background: <?php echo $linkActiveColour; ?> -o-linear-gradient(top, <?php echo $rgba; ?> 0%,rgba(0,0,0,.2) 100%); /* Opera11.10+ */
	background: <?php echo $linkActiveColour; ?> -ms-linear-gradient(top, <?php echo $rgba; ?> 0%,rgba(0,0,0,.2) 100%); /* IE10+ */
	background: <?php echo $linkActiveColour; ?> linear-gradient(top, <?php echo $rgba; ?> 0%,rgba(0,0,0,.2) 100%); /* W3C */
}

.button:hover,button:hover,
input[type="submit"]:hover,input[type="reset"]:hover,input[type="button"]:hover
.bg-hover
{
	background: <?php echo $darkActiveColour; ?>; /* Old browsers */
	background: <?php echo $darkActiveColour; ?> -moz-linear-gradient(top, rgba(255,255,255,.35) 0%, rgba(10,10,10,.4) 100%); /* FF3.6+ */
	background: <?php echo $darkActiveColour; ?> -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,.35)), color-stop(100%,rgba(10,10,10,.4))); /* Chrome,Safari4+ */
	background: <?php echo $darkActiveColour; ?> -webkit-linear-gradient(top, rgba(255,255,255,.35) 0%,rgba(10,10,10,.4) 100%); /* Chrome10+,Safari5.1+ */
	background: <?php echo $darkActiveColour; ?> -o-linear-gradient(top, rgba(255,255,255,.35) 0%,rgba(10,10,10,.4) 100%); /* Opera11.10+ */
	background: <?php echo $darkActiveColour; ?> -ms-linear-gradient(top, rgba(255,255,255,.35) 0%,rgba(10,10,10,.4) 100%); /* IE10+ */
	background: <?php echo $darkActiveColour; ?> linear-gradient(top, rgba(255,255,255,.35) 0%,rgba(10,10,10,.4) 100%); /* W3C */ }
}

/* Borders? */

/* #Buttons
================================================== */
.button,
button,
input[type="submit"],
input[type="reset"],
input[type="button"] {

	color: #eee;
  	font-weight: bold;
  	text-decoration: none;
  	text-shadow: 0 1px rgba(255, 255, 255, .75);
  	
  	display: inline-block;
  	
	border: 1px solid <?php echo $linkActiveColour; ?>;
  	border-top: 1px solid <?php echo $darkActiveColour; ?>;
  	border-left: 1px solid <?php echo $darkActiveColour; ?>;
  		
	cursor: pointer;
	line-height: normal;
	padding:<?php echo ($baseline*0.5-2) . "px " . ($baseline*0.5) . "px"; ?>;
	height:<?php echo ($baseline*2) . "px"; ?>;
}

.button:hover,button:hover,
input[type="submit"]:hover,input[type="reset"]:hover,input[type="button"]:hover {
	color: #222;
	border: 1px solid <?php echo $linkActiveColour; ?>;
  	border-top: 1px solid <?php echo $darkActiveColour; ?>;
  	border-left: 1px solid <?php echo $darkActiveColour; ?>;
  	
}

.button:active,button:active,
input[type="submit"]:active,input[type="reset"]:active,input[type="button"]:active {
	border: 1px solid <?php echo $linkActiveColour; ?>;
}

.button.full-width,button.full-width,
input[type="submit"].full-width,input[type="reset"].full-width,input[type="button"].full-width {
	width: 100%;
	padding-left: 0 !important;
	padding-right: 0 !important;
	text-align: center;
}

/* #Forms
================================================== */
input[type="color"]
{
	height: <?php echo ($baseline) . "px"; ?>;	
}
input[type="text"],
input[type="password"],
input[type="email"],
textarea,
select {
	border: 1px solid #ccc;
	padding: <?php echo ($baseline*0.5) . "px " . ($baseline*0.5) . "px "; ?>;
	outline: none;
	-moz-border-radius: 2px;
	-webkit-border-radius: 2px;
	border-radius: 2px;
	width: 210px;
	max-width: 100%;
	display: block;
	background: #fff; 
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
textarea:focus {
	border: 1px solid #aaa;
	color: #444;
	-moz-box-shadow: 0 0 3px rgba(0,0,0,.2);
	-webkit-box-shadow: 0 0 3px rgba(0,0,0,.2);
	box-shadow:  0 0 3px rgba(0,0,0,.2); 
}

textarea {
	min-height: 60px; 
}

/*
select {
	width: 220px; 
}
*/

input[type="checkbox"] {
	display: inline; 
}

/* Type stuff misplaced */

label span,
legend span {
	font-weight: normal;
	font-size: 13px;
	color: #444; 
}

